package org.elsfs.cloud.common.mybatis.ext.sql.support.executor;


import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import org.elsfs.cloud.common.mybatis.ext.db.GenericSqlExecutor;
import org.elsfs.cloud.common.mybatis.ext.sql.SqlExecutor;
import org.elsfs.cloud.common.mybatis.ext.sql.support.builder.GenericSelectSql;


/**
 * 查询分页数据SQL执行器
 *
 * @param <R> 结果类型

 */
@RequiredArgsConstructor
public class QueryPageSqlExecutor<R> extends GenericSelectSql<QueryPageSqlExecutor<R>> implements SqlExecutor<IPage<R>> {

    /**
     * 通用SQL执行器
     */
    private final GenericSqlExecutor genericSqlExecutor;
    /**
     * 分页对象
     */
    private final IPage<R> pageable;
    /**
     * 结果类
     */
    private final Class<R> clazz;

    /**
     * 执行SQL
     *
     * @return 结果
     */
    @Override
    public IPage<R> execute() {
        return this.genericSqlExecutor.selectPage(
                this.buildSqlFragment(),
                pageable,
                this.getSqlParameterManager().getSqlParameters(),
                this.clazz
        );
    }
}
